﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>

<script type="text/javascript" src='<%=Url.Content("~/Scripts/json.js")%>'></script>

<div class="float-left form-wrap" style="font-size:12px;color:#6a6b6d;">
    <input name="txtName" type="text" value="Họ tên" style="font-size:12px;color:#6a6b6d;" id="txtName" onfocus="clearName()" onblur="defaultName()" >
    <div class="float-left" style="width:160px; text-align:center">
        <span id="lblhoten" class="size11" style="color:#ff0000"></span>
    </div>
         
    <input name="txtEmail" type="text" value="Thư điện tử (bắt buộc)" id="txtEmail" 
        class="float-left size12 light40 required email" style="font-size:12px;color:#6a6b6d;" onfocus="clearEmail()" onblur="defaultEmail()">
    <div class="float-left" style="width:160px; text-align:center">
        <span id="lblEmail" class="size11" style="color:#ff0000"></span>
    </div>
    
    <input name="txtPhone" type="text" value="Số điện thoại liên hệ" id="txtPhone" class="float-left size12 light40" style="font-size:12px;color:#6a6b6d;" onfocus="clearPhone()" onblur="defaultPhone()">
    <div class="float-left" style="width:160px; text-align:center">
        <span id="labPhone" class="size11" style="color:#ff0000"></span>
    </div>
    <input name="txtTitle" type="text" value="Tiêu đề" style="font-size:12px;color:#6a6b6d;" id="txtTitle" onfocus="clearTitle()" onblur="defaultTitle()" >
    <div class="float-left" style="width:160px; text-align:center">
        <span id="lblhoten" class="size11" style="color:#ff0000"></span>
    </div>
    <textarea name="txtContent" rows="2" cols="20" id="txtContent" class="textarea size12 light40 float-left" onfocus="clearContent()" onblur="defaultContent()" style="font-family:Arial; line-height:13px;font-size:12px;color:#6a6b6d;">Nội dung (Quý khách hãy gửi các yêu cầu, thắc mắc hoặc góp ý với chúng tôi tại đây! Để thuận tiện cho việc hỗ trợ, quý khách vui lòng điền chính xác thông tin bên trên.)</textarea>
    <div class="float-left" style="width:160px;">
        <span id="lblContent" class="size11" style="color:#ff0000"></span>
    </div>

    <div class="float-left" style="width:160px; text-align:center">
        <input type="button" name="btnSubmit" value="Gửi" id="btnSubmit" onclick="sendQuestion()"
            class="size10 white bg-darkblue btn-feedback font-uppercase font-bold" style="width:116px;line-height:16px; margin-top:4px;">
    </div>
        
    <div class="float-left" style="width:160px; text-align:center">
        <img id="loading-img" src="../../Content/images/loading.gif" alt="đang xử lý ....." 
            width="25px" height="25px"/>
        <span id="lblMessage" class="size12 darkblue"></span>
    </div> 
</div>	

<script type="text/javascript">
    $("#loading-img").hide();

    function sendQuestion() {
        $("#loading-img").show();
        $("#lblMessage").html("");
        var hoTen = $("#txtName").val();
        var email = $("#txtEmail").val();
        var fone = $("#txtPhone").val();
        var title = $("#txtTitle").val();
        var body = $("#txtContent").val();
        
        var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
        if (email == '') {
            $("#lblMessage").html("Địa chỉ email không được bỏ trống!");
            $("#loading-img").hide();
            return;
        }
        else if (!emailReg.test(email)) {
            $("#lblMessage").html("Địa chỉ email không hợp lệ!");
            $("#loading-img").hide();
            return;
        }

        //var data = { emailInfo: { Name: hoTen, From: email, Fone: fone, Body: body} };
        var data = { emailInfo: hoTen + "~" + email + "~" + fone + "~" + title + "~" + body };
        var jsonData = $.toJSON(data);
//        alert(data);
        //alert(jsonData);
        $("#btnSubmit").hide();
        $.ajax({
            url: '/DatCauHoi',
            type: 'POST',
            dataType: 'json',
            data: jsonData,
            contentType: 'application/json; charset=utf-8',
            success: function(data) {
                var message = data.mess;
                $("#lblMessage").html(message);
            },
            complete: function() {
                $("#loading-img").hide();
                $("#btnSubmit").show();
            }
        });
        
    }
</script>